<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="en">
<head>
	<base href="<%=basePath%>">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>新建病例单</title>
    <link rel="stylesheet" href="static/css/common.css">
    <link rel="stylesheet" href="static/css/bootstrap.css">
    <link rel="stylesheet" href="static/css/font-awesome-4.7.css">
    <link rel="stylesheet" href="static/css/blxx.css">
    <script src="static/js/jquery-1.11.3.js"></script>
    <script src="static/js/bootstrap.js"></script>
    <script src="static/layer/layer.js"></script><!-- 弹出窗 -->
    <!--提示框-->
	<script type="text/javascript" src="static/js/jquery.tips.js"></script>
	<style>
    	.table th,
    	.table td {
    		text-align:center;
    	}
    	.table tr .center {
    		padding-top:0.7%;
    	}
    	form {
		    margin: 0;
		    margin-top:10px;
		}
    </style>
</head>

<body>
    <div class="container-fluid" style="padding-left:0;padding-right:40px;">
		<!-- 查到只有一个患者时 -->
	        <div class="row" id="row" >
	            <!-- 患者主要信息展示页面 -->
	            <div class="col-sm-offset-2 col-sm-8 col-md-offset-2 col-md-8 col-lg-offset-2 col-lg-8 main shadow">
	                <form action="" id="caseOrderForm" method="post" enctype="multipart/form-data">
	                    <!-- 患者信息 -->
	                    <div class="r1">
	                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
	                            <i>*</i>
	                            <span>姓名:</span>
	                        </div>
	                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
	                            <!-- 姓名输入框 -->
	                            <div class="col-sm-6 col-md-6 col-lg-6 box">
	                                <input type="text" class="name" placeholder="请输入患者姓名" value="${patient.name }" readonly="readonly">
	                            </div>
	                            <!-- 性别选择 -->
	                            <div class="col-sm-6 col-md-6 col-lg-6 sex">
	                                <div class="left lf">
	                                    <i>*</i>
	                                    <span>姓别:</span>
	                                </div>
	                                <div class="right">
	                                    <label id="sex">${patient.sex }</label>
	                                </div>
	                            </div>
	                        </div>
	                    </div>
	                    <!-- 年龄及联系方式 -->
	                    <div class="r2">
	                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
	                            <i>*</i>
	                            <span>年龄:</span>
	                        </div>
	                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
	                            <!-- 年龄输入框 -->
	                            <div class="col-sm-6 col-md-6 col-lg-6 box">
	                                <input type="text" class="age" placeholder="请输入患者年龄"  value="${age}" readonly="readonly">&nbsp;&nbsp; 岁
	                            </div>
	                            <!-- 联系方式 -->
	                            <div class="col-sm-6 col-md-6 col-lg-6">
	                                <div class="left lf">
	                                    <i>*</i>
	                                    <span>电话:</span>
	                                </div>
	                                <div class="right">
	                                    <input type="text" class="phone" placeholder="请输入您的联系方式" value="${patient.phone }" readonly="readonly">
	                                </div>
	                            </div>
	                        </div>
	                    </div>
	                    
	                    <!-- 医生主诉 -->
	                    <div class="r7">
	                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
	                            <span>主诉/
	                                <br>现病史:</span>
	                        </div>
	                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
	                            <textarea name="xbs" id="xbs" cols="30" rows="10" placeholder="请输入备注信息" class="textarea"></textarea>
	                        </div>
	                    </div>
	                    <!-- 收货人 -->
	                    <div class="r5">
	                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
	                            <span>体格检查:</span>
	                        </div>
	                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
	                            <span>体温</span>
	                            <input type="text" class="temperature" id="tw" name="tw">℃
	                            <span style="margin-left:20px;">体重</span>
	                            <input type="text" class="tz" id="tz" name="tz">KG
	                            <span style="margin-left:20px;">心率</span>
	                            <input type="text" class="xl" id="xl" name="xl">bpm
	                            <span style="margin-left:20px;">血压</span>
	                            <input type="text" class="tz" placeholder="收缩压" id="ssy" name="ssy">/
	                            <input type="text" class="xl" placeholder="舒张压" id="szy" name="szy">mmHg
	
	                        </div>
	                    </div>
	                    <!-- 医生诊断 -->
	                    <div class="r7">
	                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
	                            <i>*</i>
	                            <span>诊断:</span>
	                        </div>
	                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
	                            <textarea name="zd" id="zd" cols="30" rows="10" placeholder="请输入备注信息" class="textarea"></textarea>
	                        </div>
	                    </div>
	                    <!-- 添加影像资料 -->
	                    <div class="r5">
	                        <div class="col-sm-2 col-md-2 col-lg-2 lf left ">
	                            <span>添加影像资料:</span>
	                        </div>
	                        <div class="col-sm-10 col-md-10 col-lg-10 lf right">
	                            <div class="imgdiv">
	                                <div class="uploadImgDiv">
	                                    <img src="">
	                                    <input type="file" name="file" accept="img/*" onchange="fileclick(this)" title="添加图片信息">
	                                </div>
	                            </div>
	                        </div>
	                    </div>
	                    <!-- 表单提交 -->
	                    <div class="bottom col-sm-offset-5 col-sm-2 col-md-offset-5 col-md-2 col-lg-offset-5 col-lg-2">
	                        <a class="btn btn-success submit" id="submit"style="width:100%;">提&nbsp;&nbsp;&nbsp;交</a>	                        
	                        <input type="hidden" name="hzId" value="${patient.id }" class="hzId" id="hzId">
	                    </div>
	                    <div class="col-sm-offset-3 col-sm-2 col-md-offset-3 col-md-2 col-lg-offset-3 col-lg-2" style="margin-top:15px;">
	                        <a class="btn btn-info xjcf" id="xjcf" style="width:100%;">新建处方</a>
	                    </div>
	                </form>
	            </div>
	        </div>
    </div>
    <!-- 上传文件js代码 -->
    <script type="text/javascript">
    
      	 $(function(){
	      	 $(top.hangge());
	     	$('input[type=radio]:checked').css('color','#007cde');
      	 	//病历单输入框隐藏
    		//$(".main").css('display','none');
    		$("#xjcf").css('display','none');
    		//若条件查询只有一个，展示病历单输入框
    		/* var has = '${has}';
    		if(has==1){
    			$(".main").show();
    		} */
    		
    		//点击提交,添加病历单
     		$("#submit").click(function(){
     			var _reg = /^([1-9])\d{0,9}(.\d{1,2})?$/;
     			var _reg2 = /^([1-9])\d*$/;
     			//验证体温（小数）
     			if($("#tw").val().trim() !="" && !_reg.test($("#tw").val().trim())){
	     			$("#tw").tips({
		    			 side:3,
		    			 msg:'体温格式不正确',
		    			 bg:'#AE81FF',
		  	             time:2
		  	         });
	    		 	$("#zd").focus();
	    		 	return false;
     			}
     			//验证体重（小数）
     			if($("#tz").val().trim()!="" && !_reg.test($("#tz").val().trim())){
     				$("#tz").tips({
		    			 side:3,
		    			 msg:'体重格式不正确',
		    			 bg:'#AE81FF',
		  	             time:2
		  	         });
	    		 	$("#tz").focus();
	    		 	return false;
     			}
     			//验证心率（整数）
     			if($("#xl").val().trim()!="" && !_reg2.test($("#xl").val().trim())){
     				$("#xl").tips({
		    			 side:3,
		    			 msg:'心率格式不正确',
		    			 bg:'#AE81FF',
		  	             time:2
		  	         });
	    		 	$("#xl").focus();
	    		 	return false;
     			}
     			//验证收缩压（整数）
     			if($("#ssy").val().trim()!="" && !_reg2.test($("#ssy").val().trim())){
     				$("#ssy").tips({
		    			 side:3,
		    			 msg:'收缩压格式不正确',
		    			 bg:'#AE81FF',
		  	             time:2
		  	         });
	    		 	$("#ssy").focus();
	    		 	return false;
     			}
     			//验证舒张压（整数）
     			if($("#szy").val().trim()!="" && !_reg2.test($("#szy").val().trim())){
     				$("#szy").tips({
		    			 side:3,
		    			 msg:'收缩压格式不正确',
		    			 bg:'#AE81FF',
		  	             time:2
		  	         });
	    		 	$("#szy").focus();
	    		 	return false;
     			}
     			//验证诊断
     			if($("#zd").val().trim()==""){
     				$("#zd").tips({
		    			 side:3,
		    			 msg:'请输入诊断内容',
		    			 bg:'#AE81FF',
		  	             time:2
		    		 });
		    		 $("#zd").focus();
		    		 return false;
     			}
     			
     			var formData = new FormData($( "#caseOrderForm" )[0]); 
     			$.ajax({
     				url: 'caseOrder/saveCaseOrder' ,   
			          type: 'POST',    
			          data: formData,    
			          async: false,    
			          cache: false,    
			          contentType: false,    
			          processData: false,    
			          success: function (data) {    
			          	if(data.msg=="success"){
			          		layer.alert("添加成功");
			          		$("#xjcf").show();
			          		$("#xjcf").attr("href","cfOrder/findCaseOrder?id="+data.caseId+"&hzId="+$("#hzId").val());
			          	}else{
			              layer.alert(data.msg);    
			          	}
			          },    
			          error: function (data) {    
			              layer.alert(data.msg);    
			          }    
     			});
     		});
    	}); 
     
        function fileclick(obj) {
            var flag = true;
            var objUrl = getObjectURL(obj.files[0]);
            if (obj.files[0] != null) {
                var filetime = obj.files[0].lastModifiedDate;
                if (new Date(filetime).toDateString() !== new Date().toDateString()) {//判断上传图片是否是当天拍照的
                    $(obj).parent().css('background-image', 'url()');
                    if (objUrl) {
                        var img = $(obj).parent().find("img");
                        if (img.attr("src") != null && img.attr("src") != "") {
                            flag = false;
                        }
                        // 在这里修改图片的地址属性  
                        img.attr("src", objUrl);
                        img.css("opacity", 1);
                        img.css("z-index", 0);
                    }
                    if (flag) {
                        var str = '<div class="imgdiv"><div class="uploadImgDiv"><img src=""><input type="file" name="file" accept="img/*" onchange="fileclick(this)"></div></div>';
                        $(obj).parent().parent().parent().append(str);
                    }
                } else {
                    var objpar = obj.parentNode;
                    objpar.removeChild(obj);
                    $(objpar).append('<input type="file" name="file" accept="img/*" onchange="fileclick(this)"><br/>');
                }
            } else {
                $(obj).parent().css('background-image', 'url(img/icon_addphoto.png)');
            }
        }
        //建立一個可存取到該file的url  
        function getObjectURL(file) {
            var url = null;
            // 下面函数执行的效果是一样的，只是需要针对不同的浏览器执行不同的 js 函数而已  
            if (window.createObjectURL != undefined) { // basic  
                url = window.createObjectURL(file);
            } else if (window.URL != undefined) { // mozilla(firefox)  
                url = window.URL.createObjectURL(file);
            } else if (window.webkitURL != undefined) { // webkit or chrome  
                url = window.webkitURL.createObjectURL(file);
            }
            return url;
        }
    </script>
</body>

</html>
